<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Rails::Generators::ActiveModel</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            Rails::Generators::ActiveModel 
            
                <span class="parent">&lt; 
                    
                    <a href="../../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/railties/lib/rails/generators/active_model_rb.html">railties/lib/rails/generators/active_model.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p><a href="ActiveModel.html">ActiveModel</a> is a class to be implemented by
each ORM to allow <a href="../../Rails.html">Rails</a> to generate
customized controller code.</p>

<p>The <a href="../API.html">API</a> has the same methods as <a
href="../../ActiveRecord.html">ActiveRecord</a>, but each method returns a
string that matches the ORM <a href="../API.html">API</a>.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span><span class="ruby-operator">::</span><span class="ruby-constant">ActiveModel</span>.<span class="ruby-identifier">find</span>(<span class="ruby-constant">Foo</span>, <span class="ruby-string">&quot;params[:id]&quot;</span>)
<span class="ruby-comment"># =&gt; &quot;Foo.find(params[:id])&quot;</span>

<span class="ruby-constant">DataMapper</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span><span class="ruby-operator">::</span><span class="ruby-constant">ActiveModel</span>.<span class="ruby-identifier">find</span>(<span class="ruby-constant">Foo</span>, <span class="ruby-string">&quot;params[:id]&quot;</span>)
<span class="ruby-comment"># =&gt; &quot;Foo.get(params[:id])&quot;</span>
</pre>

<p>On initialization, the <a href="ActiveModel.html">ActiveModel</a> accepts
the instance name that will receive the calls:</p>

<pre class="ruby"><span class="ruby-identifier">builder</span> = <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Generators</span><span class="ruby-operator">::</span><span class="ruby-constant">ActiveModel</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&quot;@foo&quot;</span>
<span class="ruby-identifier">builder</span>.<span class="ruby-identifier">save</span> <span class="ruby-comment"># =&gt; &quot;@foo.save&quot;</span>
</pre>

<p>The only exception in <a href="ActiveModel.html">ActiveModel</a> for <a
href="../../ActiveRecord.html">ActiveRecord</a> is the use of self.build
instead of self.new.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ActiveModel.html#method-c-all">all</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>B</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ActiveModel.html#method-c-build">build</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ActiveModel.html#method-i-destroy">destroy</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ActiveModel.html#method-i-errors">errors</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>F</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ActiveModel.html#method-c-find">find</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ActiveModel.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ActiveModel.html#method-i-save">save</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>U</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="ActiveModel.html#method-i-update">update</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>name</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-all">
            
              <b>all</b>(klass)
            
            <a href="ActiveModel.html#method-c-all" name="method-c-all" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>GET index</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-all_source')" id="l_method-c-all_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2549a3b088de14c36d60de6c60c1374af75c326f/railties/lib/rails/generators/active_model.rb#L36" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-all_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/active_model.rb, line 36</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">all</span>(<span class="ruby-identifier">klass</span>)
  <span class="ruby-node">&quot;#{klass}.all&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-build">
            
              <b>build</b>(klass, params=nil)
            
            <a href="ActiveModel.html#method-c-build" name="method-c-build" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>GET new POST create</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-build_source')" id="l_method-c-build_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2549a3b088de14c36d60de6c60c1374af75c326f/railties/lib/rails/generators/active_model.rb#L50" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-build_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/active_model.rb, line 50</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">build</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">params</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">params</span>
    <span class="ruby-node">&quot;#{klass}.new(#{params})&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-node">&quot;#{klass}.new&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-find">
            
              <b>find</b>(klass, params=nil)
            
            <a href="ActiveModel.html#method-c-find" name="method-c-find" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>GET show GET edit PATCH/PUT update DELETE destroy</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-find_source')" id="l_method-c-find_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2549a3b088de14c36d60de6c60c1374af75c326f/railties/lib/rails/generators/active_model.rb#L44" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-find_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/active_model.rb, line 44</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">params</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-node">&quot;#{klass}.find(#{params})&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(name)
            
            <a href="ActiveModel.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2549a3b088de14c36d60de6c60c1374af75c326f/railties/lib/rails/generators/active_model.rb#L31" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/active_model.rb, line 31</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-ivar">@name</span> = <span class="ruby-identifier">name</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-destroy">
            
              <b>destroy</b>()
            
            <a href="ActiveModel.html#method-i-destroy" name="method-i-destroy" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>DELETE destroy</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-destroy_source')" id="l_method-i-destroy_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2549a3b088de14c36d60de6c60c1374af75c326f/railties/lib/rails/generators/active_model.rb#L81" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-destroy_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/active_model.rb, line 81</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">destroy</span>
  <span class="ruby-node">&quot;#{name}.destroy&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-errors">
            
              <b>errors</b>()
            
            <a href="ActiveModel.html#method-i-errors" name="method-i-errors" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>POST create PATCH/PUT update</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-errors_source')" id="l_method-i-errors_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2549a3b088de14c36d60de6c60c1374af75c326f/railties/lib/rails/generators/active_model.rb#L76" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-errors_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/active_model.rb, line 76</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">errors</span>
  <span class="ruby-node">&quot;#{name}.errors&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-save">
            
              <b>save</b>()
            
            <a href="ActiveModel.html#method-i-save" name="method-i-save" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>POST create</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-save_source')" id="l_method-i-save_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2549a3b088de14c36d60de6c60c1374af75c326f/railties/lib/rails/generators/active_model.rb#L59" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-save_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/active_model.rb, line 59</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">save</span>
  <span class="ruby-node">&quot;#{name}.save&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-update">
            
              <b>update</b>(params=nil)
            
            <a href="ActiveModel.html#method-i-update" name="method-i-update" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>PATCH/PUT update</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-update_source')" id="l_method-i-update_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/2549a3b088de14c36d60de6c60c1374af75c326f/railties/lib/rails/generators/active_model.rb#L64" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-update_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/generators/active_model.rb, line 64</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">update</span>(<span class="ruby-identifier">params</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-node">&quot;#{name}.update(#{params})&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    